<?php
/**
 * Created by PhpStorm.
 * Author: ljz
 * Date: 2023/5/09
 * Time: 12:01
 */

namespace App\common\models;

use Illuminate\Support\Facades\DB;

/**
 * Class CouponStore
 * @package app\backend\models
 */
class CouponStore extends BaseModel
{
    const table = 'coupon_store';

    const STATUS_WAIT = 0; //代付保证金
    const STATUS_ON_SALE = 1; //在售
    const STATUS_HALT_SALE = 2; //停售

    public function __construct()
    {

    }

    /**
     * 查询字段规则
     *
     * @return array
     */
    static public function rules()
    {
        return [];
    }

    /**
     * 添加 使用记录
     *
     * @return array
     */
    static public function add_rules()
    {
        return [
            'coupon_id' => 'required|int', // 卡券ID
            'shop_id' => 'required|string', //商家ID
            'number' => 'required|int', //发券数量
        ];
    }

    /**
     * 字段验证返回错误信息
     *
     * @return array
     */
    static public function message()
    {
        return [
            'coupon_id.required' => '卡券ID不能为空',
            'shop_id.required' => '商家ID不能为空',
            'number.required' => '发券数量不能为空',
            'coupon_id.integer' => '卡券ID数据类型错误',
            'number.integer' => '发券数量数据类型错误',
        ];
    }

    /**
     * 数据库 - 更新数据
     * @param $where //条件数组
     * @param $data //参数数组
     * @return array
     */
    static public function updatedData($where, $data)
    {
        $data = DB::table(self::table)
            ->where($where)
            ->update($data);

        return $data;
    }

    /**
     * 数据库 - 插入数据
     * @param $data //参数数组
     * @return array
     */
    static public function insertData($data)
    {
        $data = DB::table(self::table)->insert($data);
        return $data;
    }

    /**
     * 数据库 - 获取单条数据
     * @param $where
     * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder|object|null
     */
    static public function getDetail($where)
    {
        $data = DB::table(self::table)->select(['*'])->where($where)->first();
        return $data;
    }
}
